<#assign basePath=request.contextPath />
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加角色</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <#include '/common/common-css.html'>
</head>

<body>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="myForm">
                        <input type="hidden" name="id" id="id">
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><sapn class="text-danger">* </sapn>角色名：</label>
                            <div class="col-sm-8">
                                <input id="name" name="name" class="form-control" type="text">
                                <span class="help-block m-b-none">
                                	<!-- <i class="fa fa-info-circle"></i> 这里写点提示的内容 -->
                                </span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label"><sapn class="text-danger">* </sapn>描述：</label>
                            <div class="col-sm-8">
                                <input id="description" name="description" class="form-control" type="text">
                                <span class="help-block m-b-none">
                                </span>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <#include '/common/common-js.html'>
    <script type="text/javascript">
    $().ready(function() {
    	if(null != "${role}" && '' != "${role}"){
    		$("h5").text('修改角色');
    		$("#id").val("${role.id}");
    		$("#name").val("${role.name}");
    		$("#description").val("${role.description}");
    	}
    	
    	
        var e = "<i class='fa fa-times-circle'></i> ";
        $("#myForm").validate({
            rules: {
                name: {
                	"required" : !0,
                	maxlength : 5
                },
                description : {
                	"required" : !0
                }
            },
            messages: {
                name: {
                	required: e + "请输入您的用户名",
                    maxlength : e + "长度不能超过5个字符"
                },
                description : {
                	required : e + "请输入描述"
                }
            },
            submitHandler:function(form){
    			$.ajax({    
    		        type: "post",   
    		        url: "${ basePath }/role/add?t=" + Math.random(),   
    		        data: $("#myForm").serializeJson(),  
    		        contentType: "application/json; charset=utf-8",    
    		        dataType: "json",    
    		        success: function (data) { 
    		        	if(data.error){
    						layer.msg(data.msg,{icon:2,time:1000});
    					}else{
    						if(data != null){
        		        		parent.table.ajax.reload();
        		            	var index = parent.layer.getFrameIndex(window.name);
        		        		parent.layer.close(index);
        		        	}
    					}
    		        },
    		        error:function(e) {
    					console.log(e);
    				}
    		    }) 
    		}
        }); 
        
        /* $("#myForm").validate({
            rules: {
                firstname: "required",
                lastname: "required",
                username: {
                    required: !0,
                    minlength: 2
                },
                password: {
                    required: !0,
                    minlength: 5
                },
                confirm_password: {
                    required: !0,
                    minlength: 5,
                    equalTo: "#password"
                },
                email: {
                    required: !0,
                    email: !0
                },
                topic: {
                    required: "#newsletter:checked",
                    minlength: 2
                },
                agree: "required"
            },
            messages: {
                firstname: e + "请输入你的姓",
                lastname: e + "请输入您的名字",
                username: {
                    required: e + "请输入您的用户名",
                    minlength: e + "用户名必须两个字符以上"
                },
                password: {
                    required: e + "请输入您的密码",
                    minlength: e + "密码必须5个字符以上"
                },
                confirm_password: {
                    required: e + "请再次输入密码",
                    minlength: e + "密码必须5个字符以上",
                    equalTo: e + "两次输入的密码不一致"
                },
                email: e + "请输入您的E-mail",
                agree: {
                    required: e + "必须同意协议后才能注册",
                    element: "#agree-error"
                }
            }
        }); */
    });
    </script>
</body>
</html>


    